package com.tvein.sanguo.crowd.controller
{
	//flash
	//pureMVC
	import org.puremvc.as3.multicore.interfaces.ICommand;
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.utilities.fabrication.patterns.command.SimpleFabricationCommand;
	//custom
	import com.tvein.sanguo.crowd.view.CrowdMediator;
//
	public class CrowdLoad extends SimpleFabricationCommand implements ICommand
	{
		private var crowdMediator:CrowdMediator;
		
		override public function execute(notification:INotification) : void
		{
			crowdMediator = facade.retrieveMediator(CrowdMediator.NAME) as CrowdMediator;
			
			crowdMediator.crowdShell.roleClear();
			
			for (var i:int = 0; i < notification.getBody().length; i++)
			{
				if (!notification.getBody()[i].isItMe)
				{
					if (notification.getBody()[i].getVariable("roleCMD"))
					{
						var jso:Object = JSON.parse(notification.getBody()[i].getVariable("roleCMD").getStringValue());
						
						crowdMediator.crowdShell.roleAdd(notification.getBody()[i].name, notification.getBody()[i].getVariable("roleName").getStringValue(), notification.getBody()[i].getVariable("roleImage").getIntValue(), jso);
					}
				}
			}
		}
	}
}